package io.renren.modules.sys.config;

import io.renren.modules.sys.entity.SysOddsCatetoryEntity;
import io.renren.modules.sys.entity.SysOddsEntity;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 彩票页面配置
 *
 * @author wuxianji
 * @since 2017/11/7 下午2:14
 **/
@ConfigurationProperties(prefix = "spring.odds")
@Component
public class SysBottomConfig {

    /**
     * 默认退水
     */
    public static final double DEFAULT_WATER_BREAK = 0.005;

    /**
     * 提前多长时间不在允许下注。单位分钟
     */
    public static final int BOTTOM_END_TIME = 1;

    /**
     * 玩法的赔率 key:SysOddsCatetoryEntity.name_SysOddsCatetoryEntity.list.name, value:SysOddsCatetoryEntity.list.odds
     */
    private static Map<String, Double> KEY_MAP;

    /**
     * 龙虎和
     */
    private List<SysOddsCatetoryEntity> sumList;

    /**
     * 球
     */
    private List<SysOddsCatetoryEntity> ballCategorys;

    /**
     *
     */
    private List<SysOddsCatetoryEntity> specials;

    public List<SysOddsCatetoryEntity> getSumList() {
        return sumList;
    }

    public void setSumList(List<SysOddsCatetoryEntity> sumList) {
        this.sumList = sumList;
    }

    public List<SysOddsCatetoryEntity> getBallCategorys() {
        return ballCategorys;
    }

    public void setBallCategorys(List<SysOddsCatetoryEntity> ballCategorys) {
        this.ballCategorys = ballCategorys;
    }

    public List<SysOddsCatetoryEntity> getSpecials() {
        return specials;
    }

    public void setSpecials(List<SysOddsCatetoryEntity> specials) {
        this.specials = specials;
    }

    public Map<String, Double> getKeyMap() {
        if (KEY_MAP == null) {
            KEY_MAP = new HashMap<>();
            initMap(sumList, KEY_MAP);
            initMap(ballCategorys, KEY_MAP);
            initMap(specials, KEY_MAP);
        }
        return KEY_MAP;
    }

    /**
     * 初始化keyMap
     * @param odds
     * @param result
     */
    private void initMap(List<SysOddsCatetoryEntity> odds, Map<String, Double> result) {
        for (SysOddsCatetoryEntity sysOddsCatetoryEntity : odds) {
            for (SysOddsEntity sysOddsEntity : sysOddsCatetoryEntity.getList()) {
                result.put(sysOddsCatetoryEntity.getName() + "_" + sysOddsEntity.getName(), sysOddsEntity.getOdds());
            }
        }
    }
}
